% TEST_ID: LANG-EXPAND-0096
% CATEGORY: stdlib/arithmetic_ops/accumulate
% 测试 cumprod 函数

function test_cumprod()
A = 1:5;
B = cumprod(A);
assert(B ==  [1     2     6    24   120]);

A = [1 4 7; 2 5 8; 3 6 9];
B = cumprod(A);

assert(B == [
    1     4     7
    2    20    56
    6   120   504
    ]);

A = [1 3 5; 2 4 6];
B = cumprod(A,2);

assert(B == [
    1     3    15
    2     8    48
    ]);

A = [true false true; true true false];

B = cumprod(A,2);

assert(B == [
    1     0     0
    1     1     0
    ]);

A = [
    9    10     3
    10     7     6
    2     1    10
    ];

B = cumprod(A,'reverse');

assert(B == [
    180    70   180
    20     7    60
    2     1    10
    ]);

A = [1 3 NaN 2 4 NaN];
B = cumprod(A);

assert(B(1:2) == [1, 3]);
assert(isnan(B(3:3+3)));

B = cumprod(A,'omitnan');


assert(B == [1     3     3     6    24    24]);

assert(isempty(cumprod([])));

% 对空数组进行cumprod;
A = ones(0, 3, 2);
assert(size(cumprod(A)) == [0 3 2]);
assert(size(cumprod(A, 1)) == [0 3 2]);
assert(size(cumprod(A, 2)) == [0 3 2]);
assert(size(cumprod(A, 3)) == [0 3 2]);

% 测试复数
A = [1 + 1i, 2 + 1i, 3 + 1i];
B = cumprod(A);
ret = [1.0000 + 1.0000i   1.0000 + 3.0000i   0.0000 + 10.0000i];
assert(isequal(B, ret));
end
